<template>
  <div>
    <!-- 🍞面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 🪧卡片区域 -->
    <el-card>
      <el-table :data="rightsList" style="width: 100%" border stripe>
        <el-table-column label="#" type="index" width="60"></el-table-column>
        <el-table-column label="权限名称" prop="authName"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="权限等级" prop="level">
          <template #default="scope">
            <el-tag size="large" v-if="scope.row.level === '0'" type="primary"
              >一级</el-tag
            >
            <el-tag
              size="large"
              v-else-if="scope.row.level === '1'"
              type="success"
              >二级</el-tag
            >
            <el-tag size="large" v-else type="warning">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { getCurrentInstance, reactive, ref } from 'vue';
import { ElMessage } from 'element-plus';
const currentInstance = getCurrentInstance();
const { $axios } = currentInstance.appContext.config.globalProperties;

let rightsList = ref([]);
getRightsList();

async function getRightsList() {
  const { data } = await $axios.get('rights/list');
  if (data.meta.status !== 200)
    return ElMessage({
      type: 'error',
      message: '获取权限数据失败！',
      showClose: true,
    });

  rightsList.value = data.data;
}
</script>

<style scoped></style>
